﻿/**********************************弘石项目*******************************************
* 功能描述:领导驾驶舱（生产经营统计表）
* 作者:李兰祥
* 时间:2021‎年‎12‎月‎13‎日
* 
**********************************弘石项目*******************************************/
using HongStone.Domain.ContractModel;
using HongStone.Dto.ProductionDto;
using HongStone.Ince;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MiniExcelLibs;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace HongStone.API.Controllers
{
    [ApiExplorerSettings(GroupName = "Productiono")]
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProductionoController : ControllerBase
    {
        public readonly ProductionoInce _app;

        public ProductionoController(ProductionoInce app)
        {
            _app = app;
        }

        /// <summary>
        /// 显示合同额百分比(累计)
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetThecontracts(string And, string End)
        {
            return Ok(_app.GetThecontracts(And, End));
        }

        /// <summary>
        /// 部门合同额同比(月)
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetYue(string And, string End)
        {
            return Ok(_app.GetYue(And, End));
        }

        /// <summary>
        /// 部门收费同比
        /// </summary>
        /// <param name="And"></param>
        /// <param name="End"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetTongBi(string And, string End)
        {
            return Ok(_app.GetTongBi(And, End));
        }

        /// <summary>
        /// 导出Excel表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult DownLoad()
        {
            var valuest = _app.GetThecontracts("2021-01-01", "2021-12-31");
            var values = new List<Dictionary<string, string>>();
            foreach (var item in valuest)
            {
                values.Add(new Dictionary<string, string>
                {
                    { "部门名称",$"{item.Name}"},{ "年度目标",$"{item.BuBiao}"},{ "本年总额",$"{item.Zonge}"},{ "年度额百分比",$"{item.BaiFenZhi}"},{ "月度总额",$"{item.YueZong}"},{ "同比增减",$"{item.Ling}"}
                });
            }
            var memorystream = new MemoryStream();
            memorystream.SaveAs(values);
            memorystream.Seek(00, SeekOrigin.Begin);
            return new FileStreamResult(memorystream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = "生产经营统计表.xlsx"
            };
        }

        /// <summary>
        /// 合同收费详细
        /// </summary>
        /// <param name="DictionariesId"></param>
        /// <param name="ShiJian"></param>
        /// <param name="ContractName"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetThecontractss(string DictionariesId = "", string ShiJian = "", string ContractName = "")
        {
            return Ok(_app.GetThecontractss(DictionariesId, ShiJian, ContractName));
        }

        /// <summary>
        /// 计算同比增减
        /// </summary>
        /// <param name="And"></param>
        /// <param name="End"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetBiLi(string And, string End)
        {
            return Ok(_app.GetBiLi(And, End));
        }
        /// <summary>
        /// 合同与项目综合统计
        /// </summary>
        /// <param name="deptid"></param>
        /// <param name="year"></param>
        /// <param name="ji"></param>
        /// <param name="yue"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult ShowTotal(int deptid, int year, int ji, int yue)
        {
            return Ok(_app.ShowTotal(deptid, year, ji, yue));
        }
        /// <summary>
        /// 合同收款统计
        /// </summary>
        /// <param name="deptid"></param>
        /// <param name="year"></param>
        /// <param name="ji"></param>
        /// <param name="yue"></param>
        /// <param name="begintime"></param>
        /// <param name="endtime"></param>
        /// <param name="beinyear"></param>
        /// <param name="endyaer"></param>
        /// <param name="name"></param>
        /// <param name="beginedu"></param>
        /// <param name="endedu"></param>
        /// <param name="beginsalary"></param>
        /// <param name="endsalary"></param>
        /// <param name="beginjin"></param>
        /// <param name="endjin"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult ShowContractTotal(ChecksDto checksDto)
        {
            return Ok(_app.ShowContractTotal(checksDto));
        }
        /// <summary>
        /// 合同综合统计
        /// </summary>
        /// <param name="checksDto"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult ShowContractCount(ChecksDto checksDto)
        {
            return Ok(_app.ShowContractCount(checksDto));
        }
        /// <summary>
        /// 部门收费同比
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetDepartmentCharges(string And, string End)
        {
            return Ok(_app.GetDepartmentCharges(And, End));
        }

        /// <summary>
        /// 环比
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetHuan(string And, string End, string Ands, string Ends)
        {
            return Ok(_app.GetHuanQian(And, End,Ands,Ends));
        }

        /// <summary>
        /// 项目分类同比
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetFenLei(string And="2021", string End="11", string Ands="2021", string Ends="12")
        {
            return Ok(_app.GetFenLei(And, End,Ands,Ends));
        }
        /// <summary>
        /// 项目综合统计
        /// </summary>
        /// <param name="checksDto"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult ShowProjectCount(ChecksDto checksDto)
        {
            return Ok(_app.ShowProjectCount(checksDto));
        }
    }
} 
